home *** CD-ROM | disk | FTP | other *** search
/ Computer Select (Limited Edition) / Computer Select.iso / dobbs / v17n03 / oopasm.exe / FILEINFO.ASM < prev    next >
Encoding:
Assembly Source File  |  1990-07-16  |  10.9 KB  |  509 lines

  1.     .MODEL    SMALL
  2.  
  3.     INCLUDE    equates.inc
  4.     INCLUDE    instance.inc
  5.     INCLUDE    messages.inc
  6.     INCLUDE    objects.inc
  7.  
  8.     UR    EQU    5            ;Upper row
  9.     LC    EQU    15            ;Left column
  10.     LR    EQU    17            ;Lower row
  11.     RC    EQU    56            ;Right column
  12.  
  13. IF1
  14.     INCLUDE    macros.mac
  15.     INCLUDE    objects.mac
  16.     INCLUDE    cursor.mac
  17. ENDIF
  18.  
  19.     EXTRN    convertDigits:NEAR
  20.     EXTRN    findFirst:NEAR
  21.     EXTRN    getFileName:NEAR
  22.     EXTRN    longToString:NEAR
  23.     EXTRN    prtString:NEAR
  24.     EXTRN    prtString_:NEAR
  25.     EXTRN    sendMsg:NEAR
  26.  
  27.     EXTRN    Buffer:WORD
  28.     EXTRN    DBorder:WORD
  29.     EXTRN    Dispatch:WORD
  30.     EXTRN    DosError:WORD
  31.     EXTRN    FileAttr:WORD
  32.     EXTRN    FileDate:WORD
  33.     EXTRN    FileName:WORD
  34.     EXTRN    FileSize:WORD
  35.     EXTRN    FileTime:WORD
  36.     EXTRN    Hardware:WORD
  37.     EXTRN    PopUp:WORD
  38.     EXTRN    Self:WORD
  39.     EXTRN    System:WORD
  40.  
  41.  
  42.     .CODE
  43.  
  44. IF Dbug
  45.     PUBLIC    findFile
  46. ENDIF
  47. COMMENT    %
  48. ==============================================================================
  49. Gets file information from DOS.
  50.  
  51. =============================================================================%
  52. findFile    PROC    NEAR
  53.     lea        dx,FileName        ;Get ptr to file name
  54.     call        findFirst        ;Find file
  55.     jc        ff1            ;Jump if error
  56.  
  57.     send        Self,Read        ;Display file info
  58.     jmp        ff2            ;Exit
  59.  
  60. ff1:    push        ax            ;Save error code
  61.     send        Self,Clear        ;Clear window
  62.     pop        ax            ;Restore error code
  63.     push        Self            ;Save yourself
  64.     send        DosError,Error,ax    ;Handle error
  65.     pop        Self            ;Restore yourself
  66.  
  67. ff2:    ret
  68. findFile    ENDP
  69.  
  70.  
  71.  
  72. IF Dbug
  73.     PUBLIC    disFileInfo
  74. ENDIF
  75. COMMENT    %
  76. ==============================================================================
  77. Displays file information in FileInfo window.
  78.  
  79. =============================================================================%
  80. disFileInfo    PROC    NEAR
  81.     push        es
  82.     push        ds            ;Make ds and es the same
  83.     pop        es
  84.     getInst        dh,Row1,Self        ;Get window coords
  85.     getInst        dl,Col1
  86.     add        dh,RowOffset
  87.     add        dl,ColOffset
  88.  
  89.     getInst        bl,Color        ;Get window color
  90.     getInst        si,TxtPtr        ;Get field text tbl ptr
  91.  
  92.     call        disFields        ;Display fields
  93.     call        disFileName        ;Display file name
  94.     call        disFileAttr        ;Display file attribute
  95.     call        disFileDate        ;Display file creation date
  96.     call        disFileTime        ;Display file creation time
  97.     call        disFileSize        ;Display file size
  98.     pop        es
  99.     ret
  100. disFileInfo    ENDP
  101.  
  102.  
  103.  
  104. COMMENT    %
  105. ==============================================================================
  106. Displays fields for FileInfo window.
  107.  
  108. Passed:    bl - Color
  109.     cx - Lower/Right row/column
  110.     dx - Upper/Left row/column
  111.     si - Pointer to field text tbl
  112.  
  113. =============================================================================%
  114. disFields    PROC    NEAR
  115.     push        dx
  116.     mov        cx,NumOfFields
  117. dflds1:    call        prtString        ;Display string
  118.     add        dh,NumOfRows
  119.     add        si,FieldSize
  120.     loop        dflds1
  121.     pop        dx
  122.     add        dl,FieldSize+2        ;Set new left column
  123.     ret
  124. disFields    ENDP
  125.  
  126.  
  127.  
  128. COMMENT    %
  129. ==============================================================================
  130. Displays file name in FileInfo window.
  131.  
  132. Passed:    bl - Color
  133.     dx - Upper/Left row/column
  134.  
  135. =============================================================================%
  136. disFileName    PROC    NEAR
  137.     lea        si,FileName        ;Pass ptr to file name
  138.     call        prtString        ;Display string
  139.     add        dh,NumOfRows        ;Set new row
  140.     ret
  141. disFileName    ENDP
  142.  
  143.  
  144.  
  145. COMMENT    %
  146. ==============================================================================
  147. Displays file attribute in FileInfo window.
  148.  
  149. Passed:    bl - Color
  150.     dx - Upper/Left row/column
  151.  
  152. =============================================================================%
  153. disFileAttr    PROC    NEAR
  154.     push        dx
  155.     setCur        dh,dl
  156.     lea        di,Buffer
  157.     lea        si,FileAttr
  158.     mov        dl,Bptr[si]
  159.     mov        al,dl
  160.     or        al,100000b
  161.     neq        al,100000b,dfa1
  162.     lea        si,Attr1
  163.     call        disFileAttr_
  164. dfa1:    mov        al,dl
  165.     or        al,010000b
  166.     neq        al,010000b,dfa2
  167.     lea        si,Attr2
  168.     call        disFileAttr_
  169. dfa2:    mov        al,dl
  170.     or        al,001000b
  171.     neq        al,001000b,dfa3
  172.     lea        si,Attr3
  173.     call        disFileAttr_
  174. dfa3:    mov        al,dl
  175.     or        al,000010b
  176.     neq        al,000010b,dfa4
  177.     lea        si,Attr4
  178.     call        disFileAttr_
  179. dfa4:    or        dl,000001b
  180.     neq        dl,000001b,dfa5
  181.     lea        si,Attr6
  182.     call        disFileAttr_
  183. dfa5:    lea        si,Buffer        ;Pass buffer addr
  184.     call        prtString_        ;Display string
  185.     pop        dx
  186.     add        dh,NumOfRows        ;Set new row
  187.     ret
  188. disFileAttr    ENDP
  189.  
  190.  
  191.  
  192. COMMENT    %
  193. ==============================================================================
  194. Moves a text string to the text buffer for display.
  195.  
  196. Passed:    di - Next available location in Buffer
  197.     si - Address of text string
  198.  
  199. Passes:    di - Next available location in Buffer
  200.  
  201. =============================================================================%
  202. disFileAttr_    PROC    NEAR
  203.     lea        ax,Buffer
  204.     eq        ax,di,dfa_1
  205.     mov        ax,Wptr[CommaSpace]    ;Get delimiters
  206.     mov        Wptr[di-1],ax        ;Save them in buffer
  207.     inc        di            ;Poin to next location
  208. dfa_1:    lodsb
  209.     mov        Bptr[di],al
  210.     inc        di
  211.     notZero        al,dfa_1
  212.     dec        di
  213.     ret
  214. disFileAttr_    ENDP
  215.  
  216.  
  217.  
  218. COMMENT    %
  219. ==============================================================================
  220. Displays file creation date in FileInfo window.
  221.  
  222. Passed:    bl - Color
  223.     dx - Upper/Left row/column
  224.  
  225. =============================================================================%
  226. disFileDate    PROC    NEAR
  227.     push        dx
  228.     setCur        dh,dl
  229.     lea        di,Buffer
  230.     lea        si,FileDate
  231.     mov        dx,Wptr[si]
  232.     mov        ax,dx
  233.     and        ax,01Fh
  234.     mov        cl,5
  235.     shr        dx,cl
  236.     mov        cx,dx
  237.     and        cx,01Fh
  238.     push        dx
  239.     push        ax
  240.     call        disMonth
  241.     pop        ax
  242.     call        disDay
  243.     pop        dx
  244.     mov        cl,4
  245.     shr        dx,cl
  246.     and        dx,03Fh
  247.     call        disYear
  248.     lea        si,Buffer        ;Pass buffer addr
  249.     call        prtString_        ;Display string
  250.     pop        dx
  251.     add        dh,NumOfRows        ;Set new row
  252.     ret
  253. disFileDate    ENDP
  254.  
  255.  
  256.  
  257. COMMENT    %
  258. ==============================================================================
  259. Displays file creation month in FileInfo window.
  260.  
  261. Passed:    cl - Month of year
  262.     di - Next available Buffer addr
  263.  
  264. Passes:    di - Next available Buffer addr
  265.  
  266. =============================================================================%
  267. disMonth    PROC    NEAR
  268.     lea        di,Buffer
  269.     lea        si,MonthTbl
  270.     mov        ax,2
  271.     dec        cl
  272.     mul        cl
  273.     add        si,ax
  274.     mov        si,Wptr[si]
  275. dmth1:    lodsb
  276.     mov        Bptr[di],al
  277.     inc        di
  278.     notZero        al,dmth1
  279.     dec        di
  280.     ret
  281. disMonth    ENDP
  282.  
  283.  
  284.  
  285. COMMENT    %
  286. ==============================================================================
  287. Displays file creation day in FileInfo window.
  288.  
  289. Passed:    al - Day of month in BCD
  290.     di - Next available Buffer addr
  291.  
  292. Passes:    di - Next available Buffer addr
  293.  
  294. =============================================================================%
  295. disDay    PROC    NEAR
  296.     call        convertDigits        ;Convert BCD to ASCII
  297.     eq        al,30h,dd1        ;Don't display leading zero
  298.     mov        Bptr[di],al        ;Move hi-order into buffer
  299.     inc        di
  300. dd1:    mov        Bptr[di],ah        ;Move lo-order into buffer
  301.     inc        di
  302.     mov        ax,Wptr[CommaSpace]    ;Get delimiters
  303.     mov        Wptr[di],ax        ;Move into buffer
  304.     add        di,2            ;Return next available addr
  305.     ret
  306. disDay    ENDP
  307.  
  308.  
  309.  
  310. COMMENT    %
  311. ==============================================================================
  312. Displays file creation year in FileInfo window.
  313.  
  314. Passed:    dx - Year
  315.     di - Next available Buffer addr
  316.  
  317. =============================================================================%
  318. disYear    PROC    NEAR
  319.     push        bx
  320.     mov        ax,1980            ;Get current year
  321.     add        ax,dx
  322.     cwd
  323.     call        longToString        ;Convert to ASCII
  324.     pop        bx
  325.     ret
  326. disYear    ENDP
  327.  
  328.  
  329.  
  330. COMMENT    %
  331. ==============================================================================
  332. Displays file creation time in FileInfo window.
  333.  
  334. Passed:    bl - Color
  335.     dx - Upper/Left row/column
  336.  
  337. =============================================================================%
  338. disFileTime    PROC    NEAR
  339.     push        dx
  340.     setCur        dh,dl
  341.     lea        di,Buffer
  342.     lea        si,FileTime
  343.     mov        ch,0            ;Clear pm flag
  344.     mov        ax,Wptr[si]
  345.     mov        cl,11d
  346.     shr        ax,cl
  347.     mov        cl,10d
  348.     div        cl
  349.     zero        al,dft1            ;Don't display leading zero
  350.     moreThan    al,1,dft2        ;If > 1 must be pm
  351.     lessThan    ah,2,dft3        ;If 2nd digit < 2 must be am
  352. dft2:    sub        al,1            ;Don't use military time
  353.     sub        ah,2
  354.     mov        ch,1            ;Set pm flag
  355.     zero        al,dft1            ;Don't display leading zero
  356. dft3:    add        al,30h
  357.     mov        Bptr[di],al
  358.     inc        di
  359. dft1:    add        ah,30h
  360.     mov        Bptr[di],ah
  361.     inc        di
  362.     mov        Bptr[di],":"        ;Move colon into buffer
  363.     inc        di
  364.     mov        ax,Wptr[si]
  365.     and        ax,11111100000b        ;Mask off hours and seconds
  366.     mov        cl,5d
  367.     shr        ax,cl
  368.     mov        cl,10d
  369.     div        cl
  370.     add        al,30h
  371.     mov        Bptr[di],al
  372.     inc        di
  373.     add        ah,30h
  374.     mov        Bptr[di],ah
  375.     inc        di
  376.     zero        ch,dft4            ;Jump if am
  377.     mov        ax,"mp"            ;Afternoon (pm)
  378.     jmp        dft5
  379. dft4:    mov        ax,"ma"            ;Morning (am)
  380. dft5:    mov        Wptr[di],ax        ;Save am/pm
  381.     mov        Bptr[di+2],0        ;Mark end of string
  382.     lea        si,Buffer        ;Pass buffer addr
  383.     call        prtString_        ;Display numeric string
  384.     pop        dx
  385.     add        dh,NumOfRows        ;Set new row
  386.     ret
  387. disFileTime    ENDP
  388.  
  389.  
  390.  
  391. IF Dbug
  392.     PUBLIC    disFileSize
  393. ENDIF
  394. COMMENT    %
  395. ==============================================================================
  396. Displays file size in FileInfo window.
  397.  
  398. Passed:    bl - Color
  399.     dx - Upper/Left row/column
  400.  
  401. =============================================================================%
  402. disFileSize    PROC    NEAR
  403.     setCur        dh,dl            ;Position cursor
  404.  
  405.     lea        di,Buffer        ;Pass buffer addr
  406.     lea        si,FileSize        ;Get ptr to file size
  407.     mov        ax,Wptr[si]        ;Pass long integer
  408.     mov        dx,Wptr[si+2]        ;In dx:ax
  409.  
  410.     push        bx
  411.     call        longToString        ;Convert to ASCII
  412.     pop        bx
  413.  
  414.     lea        si,Buffer        ;Pass buffer addr
  415.     call        prtString_        ;Display numeric string
  416.     lea        si,Bytes        ;Pass ptr to description
  417.     call        prtString_        ;Display numeric string
  418.     ret
  419. disFileSize    ENDP
  420.  
  421.  
  422.  
  423.     .DATA
  424.  
  425.  
  426. FieldTxtTbl    LABEL    WORD
  427.         DB    "File Name: ",0
  428.         DB    "Attributes:",0
  429.         DB    "File Date: ",0
  430.         DB    "File Time: ",0
  431.         DB    "File Size: ",0
  432.  
  433. FieldSize    EQU    12            ;Number of bytes per field
  434. NumOfFields    EQU    05            ;Number of fields
  435. NumOfRows    EQU    02            ;Number of rows between fields
  436.  
  437. Attr1        DB    "Archive",0        ;File attribute descriptions
  438. Attr2        DB    "Subdirectory",0
  439. Attr3        DB    "Volume Label",0
  440. Attr4        DB    "System",0
  441. Attr5        DB    "Hidden",0
  442. Attr6        DB    "Read Only",0
  443.  
  444. January        DB    "January ",0
  445. February    DB    "February ",0
  446. March        DB    "March ",0
  447. April        DB    "April ",0
  448. May        DB    "May ",0
  449. June        DB    "June ",0
  450. July        DB    "July ",0
  451. August        DB    "August ",0
  452. September    DB    "September ",0
  453. October        DB    "October ",0
  454. November    DB    "November ",0
  455. December    DB    "December ",0
  456.  
  457. MonthTbl    LABEL    WORD
  458.         DW    OFFSET January
  459.         DW    OFFSET February
  460.         DW    OFFSET March
  461.         DW    OFFSET April
  462.         DW    OFFSET May
  463.         DW    OFFSET June
  464.         DW    OFFSET July
  465.         DW    OFFSET August
  466.         DW    OFFSET September
  467.         DW    OFFSET October
  468.         DW    OFFSET November
  469.         DW    OFFSET December
  470.  
  471.  
  472. MonthSize    EQU    11            ;Length of month text strings
  473. CommaSpace    DB    ", "
  474. Bytes        DB    " Bytes",0
  475.  
  476. defDispTbl    FileInfo,\
  477.     <0,0,3,0,0,0,0,System,Reset>,\
  478.     <0,68,3,0,0,0,0,FileInfo,Clear,System,Refresh,System,Read>,\
  479.     <Nil,Nil,1,UR,LC,LR,RC,FileInfo,Clear>,\
  480.     <0,Nil,Nil,0,0,24,79,Hardware,Refresh>
  481.  
  482.  
  483. defMsg    FileInfo,\
  484.     Refresh,\
  485.     <getFileName,,findFile>
  486.  
  487. defMsg    FileInfo,\
  488.     Read,\
  489.     <disFileInfo,,>
  490.  
  491. defObj    FileInfo,\
  492.     <Dispatch,PopUp,DBorder>,\
  493.     <Row1,1,UR,\
  494.     Col1,1,LC,\
  495.     Row2,1,LR,\
  496.     Col2,1,RC,\
  497.     Color,1,17h,\
  498.     Unused,1,Nil,\
  499.     TxtPtr,2,FieldTxtTbl,\
  500.     InxPtr,2,Nil,\
  501.     MasterObj,2,Nil,\
  502.     DispTbl,2,FileInfoDispTbl>,\
  503.     <Refresh,Read,Clear>
  504.  
  505.  
  506.  
  507.  
  508.     END
  509.